'use strict';

const Controller = require('egg').Controller;

class StudentController extends Controller {
    //获取
    async list() {
        let {ctx,service} = this;
        let {pagenum=1,limit=2,username,num,classNum} = ctx.query;
        let list = await service.student.list(pagenum,limit,username,num,classNum);
        let total = await service.student.total(username,num,classNum);
        ctx.body = {
            code:1,
            data:list,
            total:total[0]['count(*)']
        }
    }
    //删除
    async del(){
        let {ctx,service} = this;
        let {id} = ctx.query;
        if(id){
            try{
                await service.student.del(id);
                ctx.body = {
                    code:1,
                    msg:'删除成功'
                }
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:e
                }
            }
        }else{
            ctx.body = {
                code:0,
                msg:'参数有误'
            }
        }
    }
}

module.exports = StudentController;
